﻿Imports System.Data.SqlClient

Public Class NhaSanXuatDAO
    Public Shared Function Insert(ByVal nsx As NhaSanXuatDTO) As Integer
        Dim str = String.Format("Insert into NHASANXUAT(MaNhaSX,TenNhaSX) values ('{0}',N'{1}')", nsx.TenNhaSX, nsx.TenNhaSX)
        Dim connect As SqlConnection = DataProvider.ConnectDB("QuanLyHangHoa")
        connect.Open()
        Dim cmd As New SqlCommand(str, connect)
        cmd.CommandType = CommandType.Text
        Dim result As Integer = 1
        Try
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            result = 0
        End Try

        Return result
    End Function

    Public Shared Function Delete(ByVal maNSX As String) As Integer
        Dim result As Integer = 1
        Dim StrSql As String
        StrSql = "Delete from NHASANXUAT where MaNhaSX = '" & maNSX & "'"
        Try
            SQLProvider.ExecNoneQuery(StrSql)
        Catch ex As Exception
            result = 0
        End Try
        Return result
    End Function


    Public Shared Function Select_All() As DataTable
        Dim dt As DataTable
        Dim StrSql As String
        StrSql = "Select * from NHASANXUAT"
        dt = SQLProvider.ExecQuery(StrSql)
        Return dt
    End Function

    Public Shared Function Select_By_Ma(ByVal maNSX As String) As DataTable
        Dim dt As DataTable
        Dim StrSql As String
        StrSql = "Select * from NHASANSUAT where MaLoai = '" & maNSX & "'"
        dt = SQLProvider.ExecQuery(StrSql)
        Return dt
    End Function
End Class
